package cn.doctor.assistant.pad;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

import cn.doctor.assistant.pad.entity.AssUser;
import cn.doctor.assistant.pad.im.IMApplication;

/**
 * Created by jiaolf on 2016/2/22.
 */
public class MyApplication extends IMApplication {

    private static MyApplication instance;
    private Activity mCurrActivity;

    public static MyApplication getInstance() {
        return instance;
    }

    public Activity getCurrentActivity() {
        return this.mCurrActivity;
    }

    // 当前登录的助理用户
    public AssUser mAssistUser;

    // 助理对应的医生列表
    public List<AssUser> mDoctors;

    // 当前选择的医生
    public AssUser mCurrDoctor;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
    }

    public void enter(Activity activity) {
        this.mCurrActivity = activity;
    }

    //---------------- 助理当前选择的医生 -----------------------------
    public interface IDoctorChangedListener{
        void updateDoctor(AssUser doctor);
    }

    private List<IDoctorChangedListener> mDoctorChangedListeners = new ArrayList<>();

    public void addDoctorChangedListener(IDoctorChangedListener listener) {
        if (!mDoctorChangedListeners.contains(listener)) {
            mDoctorChangedListeners.add(listener);
        }
    }

    public void switchCurrentDoctor(int position) {
        mCurrDoctor = mDoctors.get(position);
        for (IDoctorChangedListener listener : mDoctorChangedListeners) {
            listener.updateDoctor(mCurrDoctor);
        }
    }
}
